<extend name="Public/base" />

<block name="body">
	<div class="main-title cf">
		<h2><if condition="ACTION_NAME eq 'addaction'">新增<else/>编辑</if>行为</h2>
	</div>
	<!-- 表单 -->
    <div class="with-padding">
        <form id="form" action="{:U('saveAction')}" method="post" class="form-horizontal">
            <div class="form-item cf">
                <label class="item-label">行为标识<span class="check-tips">（输入行为标识 英文字母）</span></label>
                <div class="controls">
                    <input type="text" class="text input-large form-control form-input-width" name="name" value="{$data.name}">
                </div>
            </div>
            <div class="form-item cf">
                <label class="item-label">行为名称<span class="check-tips">（输入行为名称）</span></label>
                <div class="controls">
                    <input type="text" class="text input-large form-control form-input-width" name="title" value="{$data.title}">
                </div>
            </div>
            <div class="form-item cf">
                <label class="item-label">行为类型<span class="check-tips">（选择行为类型）</span></label>
                <div class="controls">
                    <select name="type" class=" form-control form-select-size">
                        <volist name=":get_action_type(null,true)" id="vo">
                            <option value="{$key}">{$vo}</option>
                        </volist>
                    </select>
                </div>
            </div>
            <div class="form-item cf">
                <label class="item-label">行为描述<span class="check-tips">（输入行为描述）</span></label>
                <div class="controls">
                    <label class="textarea input-large "><textarea name="remark" class=" form-control form-text-area-size">{$data.remark}</textarea></label>
                </div>
            </div>



            <div class="form-item cf">
                <label class="item-label">行为规则<span class="check-tips">（输入行为规则，不写则只记录日志）</span></label>
                <div class="controls action_rule">
                    <php>
                        $score = D('Ucenter/Score')->getTypeList(array('status'=>1));
                        $data['rule'] =   unserialize( $data['rule']);
                    </php>

                    <php>if(empty($data['rule'])){</php>
                    暂无规则
                    <php>}</php>
                    <volist name="data['rule']" id="rule">
                        <div style="margin-bottom: 10px">
                            <input class="form-control" name="action_rule[table][]" value="{$rule.table}" title="所执行的表，默认是member" style="width: 100px;display: inline-block">
                            <select class="form-control"  name="action_rule[field][]" title="执行的积分" style="width: 100px;display: inline-block" >
                                <option value="0">请选择</option>
                                <volist name="score" id="s">
                                    <option value="{$s.id}" <if condition="$s['id'] eq $rule['field']">selected</if>>{$s.title}</option>
                                </volist>
                            </select>
                            <input type="text"  name="action_rule[rule][]" title="积分的操作，负数表示减积分。" value="{$rule.rule}" class=" form-control" style="width: 100px;display: inline-block"/>
                            <input class="form-control"  name="action_rule[cycle][]" title="周期" value="{$rule.cycle}" style="width: 100px;display: inline-block">
                            <input class="form-control"  name="action_rule[max][]"  title="最大限制" value="{$rule.max}" style="width: 100px;display: inline-block">
                            <a href="javascript:" data-row="del_rule">删除规则</a>

                        </div>
                    </volist>


                </div>
                <a href="javascript:" data-row="add_rule">新增规则</a>
            </div>



            <div class="form-item cf">
                <label class="item-label">日志规则<span class="check-tips">（记录日志备注时按此规则来生成，支持[变量|函数]。目前变量有：user,time,model,record,data）</span></label>
                <div class="controls">
                    <label class="textarea input-large"><textarea name="log" class=" form-control form-text-area-size">{$data.log}</textarea></label>
                </div>
            </div>

            <div class="form-item">
                <input type="hidden" name="id" value="{$data.id}"/>
                <button type="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定</button>
                <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
            </div>
        </form>
    </div>




    <div id="rule_list" style="display: none">
        <div style="margin-bottom: 10px">
            <input class="form-control"  name="action_rule[table][]" value="member" title="所执行的表，默认是member" style="width: 100px;display: inline-block">
            <select class="form-control"  name="action_rule[field][]" title="执行的积分" style="width: 100px;display: inline-block" >
                <option value="0">请选择</option>
                <volist name="score" id="s">
                    <option value="{$s.id}">{$s.title}</option>
                </volist>
            </select>
            <input type="text"  name="action_rule[rule][]" title="积分的操作，负数表示减积分。" value="0" class=" form-control" style="width: 100px;display: inline-block"/>
            <input class="form-control"  name="action_rule[cycle][]" title="周期" value="24" style="width: 100px;display: inline-block">
            <input class="form-control"  name="action_rule[max][]"  title="最大限制" value="1" style="width: 100px;display: inline-block">
            <a href="javascript:" data-row="del_rule">删除规则</a>
        </div>
    </div>
</block>

<block name="script">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" charset="utf-8">
	Think.setValue('type',{$type|default=1});
    //导航高亮
    highlight_subnav('{:U('User/action')}');
</script>

<script>
    $(function(){
        rebind();
    })

    var rebind = function(){
        add_rule();
        del_rule();
    }
    var add_rule = function(){

        $('[data-row="add_rule"]').unbind('click');
        $('[data-row="add_rule"]').click(function(){
            $('.action_rule').append($('#rule_list').html())
            rebind();
        })

    }

    var del_rule = function(){
        $('[data-row="del_rule"]').unbind('click');
        $('[data-row="del_rule"]').click(function(){
            $(this).closest('div').remove();
            rebind();
        })
    }

</script>


</block>
